const express = require('express');
const ReactSSR = require('react-dom/server');
const fs = require('fs');
const bodyParser = require('body-parser');
const session = require('express-session');
const favicon = require('serve-favicon');
const path = require('path');
const app = express();

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:false}));
app.use(session({
	maxAge : 10 * 60 * 1000,
	name : 'tid',
	resave : false,
	secret : 'Caroline'
}));

app.use('/api/user',require('./util/handle-login'))
app.use('/api',require('./util/proxy'))

const isDev = process.env.NODE_ENV == "development"

app.use(favicon(path.join(__dirname,'../favicon.ico')))


// if (!isDev ) {
// 	const serverEntry = require('../dist/server-entry').default;
// 	const template = fs.readFileSync(path.join(__dirname , '../dist/index.html'),'utf8');
// 	app.use('/public',express.static(path.join(__dirname,'../dist')))
// 	app.get('*',function(req,res){
// 		const appString = ReactSSR.renderToString(serverEntry);
// 		res.send(template.replace('<!-- app -->',appString));
// 	});
// }else{
	const devStatic = require('./util/dev-static');
	devStatic(app);
// }



app.listen('3333',function(){
	console.log('server is start at 3333');
})